Package vg.userInterface.scaling

Source Code of vg.userInterface.scaling.ZoomPanel

package vg.userInterface.scaling;

import java.util.Observable;

import javax.swing.JComponent;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import vg.core.AUserInterface;
import vg.core.AUserInterfaceElement;
import vg.core.IGraphView;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventChangeView;
import vg.userInterface.scaling.components.ZoomBox;
import vg.userInterface.scaling.components.ZoomIn;
import vg.userInterface.scaling.components.ZoomOut;

public class ZoomPanel extends AUserInterfaceElement {
  // Mutex
  private final Object theMutexObject;
  // Main components
  private final ZoomIn zoomIn;
  private final ZoomOut zoomOut;
  private final ZoomBox zoomBox;
  private final JToolBar toolBar;
  // Parameter
  private final AUserInterface userInterface;
  /**
   * Constructor.
   */
  public ZoomPanel(final AUserInterface userInterface) {
    super("Zoom panel", null);
    // init parameter
    this.userInterface = userInterface;
    // init mutex
    this.theMutexObject = new Object();
    // init components
    this.zoomIn = new ZoomIn();
    this.zoomOut = new ZoomOut();
    this.zoomBox = new ZoomBox();
    //this.toolBar = new JPanel(new GridBagLayout());
    this.toolBar = new JToolBar();
    this.toolBar.setFloatable(false);
   
    this.toolBar.add(this.zoomBox.getView());
    this.toolBar.add(this.zoomIn.getView());
    this.toolBar.add(this.zoomOut.getView());
       
    this.userInterface.addInstrument(this);
  }
  public void update(Observable o, Object arg) {
    synchronized (this.theMutexObject) {
      if(arg instanceof AUIEvent) {
        AUIEvent event = (AUIEvent)arg;
        switch (event.getType()) {
          case DEF_CHANGE_UI_STYLE: {
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                synchronized (ZoomPanel.this.theMutexObject) {
                  SwingUtilities.updateComponentTreeUI(ZoomPanel.this.toolBar);
                }
              }
            });
            break;
          }
          case DEF_CHANGE_VIEW:
          {
            UIEventChangeView bufEvent = (UIEventChangeView)event;
            IGraphView igv = bufEvent.getView();
            this.zoomIn.changeView(igv);
            this.zoomOut.changeView(igv);
            this.zoomBox.changeView(igv);
            break;
          }
        }
      }
    }
  }
  public JComponent getView() {
    return(this.toolBar);
  }
}
TOP

Related Classes of vg.userInterface.scaling.ZoomPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.